import { getTableInfo, addClient, deleteClient } from '../../api/appClient'

const state = {
  tableData: [],
  total: '',
  tbVersionDTO:
  {
    versionCode: '',
    versionDesc: '',
    versionName: '',
    versionUrl: ''
  }
}

const mutations = {
  // 设置更新列表
  update_list (state, tableData) {
    state.tableData = tableData
  },
  // 总数
  list_count (state, total) {
    state.total = total
  }
}

const actions = {
  // 刷新列表
  updateTable (context, params) {
    return new Promise((resolve, reject) => {
      getTableInfo(params).then(res => {
        if (res.data.code === (200 || '200')) {
          context.commit('update_list', res.data.data.data)
          context.commit('list_count', res.data.data.count)
        }
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  // 新增App客户端文件
  addClientData (context, params) {
    return new Promise((resolve, reject) => {
      addClient(params).then(res => {
        if (res.data.code === (200 || '200')) {
        }
        resolve(res)
      })
        .catch(err => {
          reject(err)
        })
    })
  },
  // 删除App客户端文件
  deleteClientData (context, params) {
    return new Promise((resolve, reject) => {
      deleteClient(params).then(res => {
        if (res.data.code === (200 || '200')) {
        }
        resolve(res)
      })
        .catch(err => {
          reject(err)
        })
    })
  }
}

export default {
  namespaced: true,
  actions,
  state,
  mutations
}
